package com.zoshine.zzg.service;

import com.zoshine.zzg.dao.AccountDao;
import com.zoshine.zzg.dao.OrganizationDao;
import com.zoshine.zzg.exception.AppException;
import com.zoshine.zzg.exception.ErrorMessage;
import com.zoshine.zzg.pojo.Account;
import com.zoshine.zzg.pojo.Organization;
import com.zoshine.zzg.pojo.pojostatus.CommonStatus;
import com.zoshine.zzg.util.idworker.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 账户信息服务
 * @author 田沛凌
 * @time 2017年7月7日 下午5:06:16
 */
@Service
@Transactional
public class AccountService extends BaseService<Account>{
    private AccountDao accountDao;
    private OrganizationDao organizationDao;
    @Autowired
    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }
    @Autowired
    public void setOrganizationDao(OrganizationDao organizationDao) {
        this.organizationDao = organizationDao;
    }

//    /**
//     * 删除账户
//     * @param accountId 账户编号
//     */
//    public void delAccount(Long accountId) {
//        if(accountId == null){
//            throw new AppException(ErrorMessage.ACCOUNT_ID_CAN_NOT_BE_NULL);
//        }
//        accountDao.delete(accountId);
//    }
//
//    /**
//     * 新增账户
//     * @param account 新增账户
//     */
//    @Override
//    public Account add(Account account) {
//        //为空判断
//        if(null == account.getOrgId()){
//            throw new AppException(ErrorMessage.ORG_ID_CAN_NOT_NULL);
//        }
//        if(null == account.getStatus()){
//            throw new AppException(ErrorMessage.ACCOUNT_STATUS_CAN_NOT_BE_NULL);
//        }
//        if(null == account.getMoney()){
//            throw new AppException(ErrorMessage.ACCOUNT_MONEY_CAN_NOT_BE_NULL);
//        }
//        //值判断
//        Account selectByOrgId = accountDao.selectByOrgId(account.getOrgId());
//        if(selectByOrgId != null){
//            throw new AppException(ErrorMessage.ORG_NAME_CAN_NOT_REPEAT);
//        }
//        Organization organization = organizationDao.selectByPrimaryKey(account.getOrgId());
//        if(organization == null){
//            throw new AppException(ErrorMessage.MODEL_CAN_NOT_FOUND);
//        }
//
//        account.setId(baseIdWorker.createId());
//        account.setStatus(CommonStatus.VALID.getValue());
//        account.setOrgName(organization.getOrgName());
//        account.setCreateTime(new Date());
//        account.setUpdateTime(new Date());
//        accountDao.insert(account);
//        return account;
//    }
//
//    /**
//     * 查询账户
//     * @param accountId 账户编号
//     * @return Account
//     */
//    public Account getAccount(Long accountId) {
//        if(accountId == null){
//            throw new AppException(ErrorMessage.ACCOUNT_ID_CAN_NOT_BE_NULL);
//        }
//        return accountDao.selectOne(accountId);
//    }
//
//    /**
//     * 修改账户
//     * @param account 账户信息
//     */
//    public void editAccount(Account account) {
//        if(null == account.getAccountId()){
//            throw new AppException(ErrorMessage.ACCOUNT_ID_CAN_NOT_BE_NULL);
//        }
//        if(null == account.getOrgId()){
//            throw new AppException(ErrorMessage.ORG_ID_CAN_NOT_NULL);
//        }
//        if(null == account.getStatus()){
//            throw new AppException(ErrorMessage.ACCOUNT_ID_CAN_NOT_BE_NULL);
//        }
//        Organization organization = organizationDao.selectOne(account.getOrgId());
//        if(organization == null){
//            throw new AppException(ErrorMessage.MODEL_CAN_NOT_FOUND);
//        }
//        Account temp = accountDao.selectOne(account.getAccountId());
//        temp.setOrgId(account.getOrgId());
//        temp.setOrgName(organization.getOrgName());
//        temp.setStatus(account.getStatus());
//        temp.setUpdateTime(new Date());
//        accountDao.update(temp);
//    }
//
//    /**
//     * 查询账户集合
//     * @param account
//     * @return selectList
//     */
//    public List<Account> listAccount(Account account) {
//        return accountDao.selectList(account);
//    }

}
